package Service;

import Entity.User;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserDao, User> implements UserService {

    @Autowired
    private UserDao userDao;


    @Override
    public User getUserById ( Integer id ) {
        return userDao.selectById ( id );
    }

    @Override
    public List<User> getAllUser ( ) {
        return userDao.selectList ( null );
    }

    @Override
    public Boolean updateUserInfo ( User user ) {
        return userDao.updateById ( user ) > 0;
    }

    @Override
    public Boolean saveUser ( User user ) {
        return userDao.insert ( user ) > 0;
    }


    @Override
    public Boolean deleteUserById ( Integer id ) {
        return userDao.deleteById ( id ) > 0;
    }

    @Override
    public User login ( Integer id , String password ) {
        User currentUser = userDao.selectById ( id );
        if (currentUser != null) {
            if (currentUser.getPassword ().equals ( password )) {
                System.out.println ( "登陆成功！" );
                return currentUser;
            } else {
                System.out.println ( "密码输入错误,登陆失败！" );
                return null;
            }
        } else {
            System.out.println ( "无此ID号，是否注册?" );
            return null;
        }
    }

}
